/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId]) {
/******/ 			return installedModules[moduleId].exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// define getter function for harmony exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		if(!__webpack_require__.o(exports, name)) {
/******/ 			Object.defineProperty(exports, name, {
/******/ 				configurable: false,
/******/ 				enumerable: true,
/******/ 				get: getter
/******/ 			});
/******/ 		}
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 21);
/******/ })
/************************************************************************/
/******/ ({

/***/ 21:
/***/ (function(module, exports, __webpack_require__) {

module.exports = __webpack_require__(22);


/***/ }),

/***/ 22:
/***/ (function(module, exports) {

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

$(function ($) {
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    //取消页面默认右键事件
    $(document).on('contextmenu', function () {
        return false;
    });
    $('.chat-list li').each(function () {
        $(this).data('sort') == 1 ? $(this).addClass('top') : $(this).removeClass('top');
    });
    if (localStorage.num) {
        localStorage.clear();
    }
    var $chat_bg = $('.chat-bg'),
        $chat_wrap = $('.chat-wrap');
    var rs = {
        room_more_taggle: true,
        $oEditnotice: $('span.edit-notice'),
        $oMore: $('#room-setting-more'),
        $oRename: $('input.rename-title'),
        $oOut: $('div.out'),
        Plus: '#plus',
        Reduce: '#reduce'
    };
    var doms = {
        $oTitle: $('.chat-wrap .header .name'),
        $oCon: $('#info-content'),
        $oNavBox: $('#nav-box')
    };
    var set_focus = function set_focus(el) {
        el = el[0];
        el.focus();
        var range = document.createRange();
        range.selectNodeContents(el);
        range.collapse(false);
        var sel = window.getSelection();
        sel.removeAllRanges();
        sel.addRange(range);
    };
    var send = function send(txt, roomId) {
        if (txt.length > 0 && txt != "") {
            var $oLi = doms.$oCon.children('li');
            if ($oLi.length === 0) {
                $('.empty-info').hide();
            }
            $.ajax({
                type: "post",
                url: "home/send",
                data: { 'txt': txt, roomId: roomId },
                success: function success(data) {
                    var args = { rId: roomId, dlgId: data.id, user: data.user, txt: txt, role: 'ask' };
                    dialoge(args);
                    scrolltToBottom();
                },
                error: function error(data) {
                    console.log(data.responseJSON.errors);
                }
            });
            $('.txt-box #textarea').text('');
        }
    };
    var scrolltToBottom = function scrolltToBottom() {
        var scrollTop = doms.$oCon[0].scrollHeight;
        doms.$oCon.scrollTop(scrollTop);
    };
    var dialoge = function dialoge(_ref) {
        var args = _objectWithoutProperties(_ref, []),
            _ref$$el = _ref.$el,
            $el = _ref$$el === undefined ? $('#info-content') : _ref$$el;

        console.log(args);
        var html = '<li class="dialogue ' + args.role + '" data-id="' + args.dlgId + '">\n                            <img data-id="' + args.user.id + '" class="head-pic" src="' + args.user.url + '" title="\u70B9\u51FB\u67E5\u770B\u7528\u6237\u4FE1\u606F"><em></em>\n                            <div class="txt" data-self="' + args.user.id + '" data-id="' + args.dlgId + '">' + args.txt + '</div>\n                            <span class="time">' + args.user.time + '</span>\n                        </li>',
            $oRoom = $('.chat-side li.choose[data-id=' + args.rId + ']'),
            $oSession = $('#sessionStorage');
        $oRoom.children('div.info').children('span.con').html(args.txt);
        $oRoom.children('div.time').children('time').text(args.time);
        $oSession.length > 0 ? $oSession.append(html) : $el.append(html);
        sessionStorage[args.rId] ? sessionStorage[args.rId] += html : sessionStorage[args.rId] = html;
    };
    var dropload = function dropload(keyword, roomId) {
        var $his = $("#info-history");
        $("#info-history ul").children().remove();
        var page = 0,
            size = 10;

        $his.dropload({
            distance: 10, //拉动距离
            threshold: 10,
            domDown: {
                domClass: 'dropload-down',
                domRefresh: '<p class="dropload-refresh">查看更多</p>',
                domLoad: '<p class="dropload-load"><span class="loading"></span>加载中...</p>',
                domNoData: '<p class="dropload-noData">暂无更多</p>'
            },
            loadDownFn: function loadDownFn(me) {
                page++;
                getHistory(keyword, me, page, size, roomId);
            }
        });
    };
    var getHistory = function getHistory(keyword, me, page, size, roomId) {
        var html = '',
            $info_his = $('#info-history ul');
        $.post('home/getHistory', { txt: keyword, page: page, size: size, roomId: roomId }, function (data) {
            var res = data.dialogue;
            if (res.length > 0) {
                res.forEach(function (v) {
                    html += '<li class="dialogue ans" data-id="' + v.id + '">\n                                            <img data-id="' + v.user_id + '" class="head-pic" src="' + v.url + '" title="\u70B9\u51FB\u67E5\u770B\u7528\u6237\u4FE1\u606F">\n                                            <div class="info">\n                                                <div class="right-t">\n                                                    <span class="his-name">' + v.user_name + '</span>\n                                                    <span class="his-time">' + v.time + '</span>\n                                                </div>\n                                                <div data-type="his" class="txt" data-self="' + v.self + '" data-id="' + v.id + '">' + v.txt + '</div>\n                                            </div>\n                                        </li>';
                });
            } else {
                me.lock(); // 无数据
                me.noData();
                me.resetload();
            }
            // 插入数据到页面，放到最后面
            $info_his.append(html);
            // 每次数据插入，必须重置
            me.resetload();
        });
    };
    doms.$oNavBox.click(function (e) {
        var $oEm = $('#emotion');
        if (e.offsetX > 120 && e.offsetX < 136 && e.offsetY > 8 && e.offsetY < 26) {
            $('#history').show();
            var keyword = $('#his-search').val().toString().trim();
            $(".dropload-down").remove();
            var roomId = $('li.choose').data('id');
            dropload(keyword, roomId);
        }
        if (e.offsetX > 21 && e.offsetX < 38 && e.offsetY > 8 && e.offsetY < 26) {
            $oEm.show().css({
                left: e.pageX,
                top: e.pageY - 280
            });
            $(document).one("click", function (e) {
                $oEm.hide();
            });
            e.stopPropagation();
        }
    });
    rs.$oMore.click(function () {
        var $oRS = $('.room-setting');
        if (rs.room_more_taggle) {
            $('.chat-wrap').css('border-right', 'none');
            $oRS.animate({
                'right': '-250px'
            }, 300);
        } else {
            $oRS.animate({
                'right': '0'
            }, 300);
        }
        rs.room_more_taggle = !rs.room_more_taggle;
    });
    $(document).on('click', rs.Plus, function () {
        var _$$data = $(this).data(),
            id = _$$data.id,
            type = _$$data.type;

        $('#addUser-wrap').Room({
            roomId: id,
            type: 1,
            confirm: function confirm(ids) {
                $.ajax({
                    type: 'get',
                    data: { id: id, ids: ids, type: type },
                    url: 'home/addUsers',
                    success: function success(data) {
                        if (type == 0) {
                            var names = data.names.join(','),
                                html = '';
                            $('#info-content').tips('label', {
                                txt: '\u4F60\u9080\u8BF7\u4E86"' + names + '"\u52A0\u5165\u4E86\u7FA4\u804A'
                            });
                            data.users.forEach(function (v) {
                                html += '<li><img src="' + v.url + '" alt=""><span>' + v.name + '</span></li>';
                            });
                            $('ul.room-users').append(html);
                        } else {
                            $('ul.chat-list').append('<li data-id="' + data.id + '">\n                                                <img src="' + data.url + '" alt="">\n                                                <div class="info">\n                                                    <span class="title">' + data.name + '</span>\n                                                   <span class="con"></span>\n                                               </div>\n                                               <div class="time">\n                                                   <time></time>\n                                               </div>\n                                           </li>');
                            $('.chat-setting i.chat').click();
                            $('.chat-side .chat-list li[data-id=' + data.id + ']').click();
                        }
                    }
                });
            }
        });
    });
    $(document).on('click', rs.Reduce, function () {
        //TODO:Reduce
        var roomId = $(this).data('id');
        $('#addUser-wrap').Room({
            roomId: roomId,
            btn_confirm: { txt: '删除', class: 'chat-btn-danger' },
            type: 2,
            confirm: function confirm(ids) {
                $('#info-tip').tips('tip', {
                    txt: '\u786E\u5B9A\u8981\u5220\u9664\u7FA4\u6210\u5458?',
                    confirm_txt: '删除',
                    btn_cancel: true,
                    confirm: function confirm() {
                        $.ajax({
                            type: 'get',
                            data: { roomId: roomId, ids: ids },
                            url: 'home/reduceUsers',
                            success: function success(data) {
                                $('ul.room-users li').each(function () {
                                    ids.includes($(this).data('id')) && $(this).remove();
                                });
                            }
                        });
                    }
                });
            }
        });
    });
    rs.$oRename.focus(function () {
        sessionStorage.oldTitle = $(this).val();
    });
    rs.$oRename.blur(function () {
        var roomId = $(this).data('id'),
            val = $(this).val();
        if (val != sessionStorage.oldTitle) {
            $.post("home/roomRename", { roomId: roomId, title: val }, function (data) {
                var txt = '你修改群名为 "' + val + '"';
                $('.chat-list li[data-id=' + roomId + '] .title').text(val);
                doms.$oTitle.text(val);
                doms.$oCon.tips('label', { txt: txt });
                scrolltToBottom();
            });
        }
    });
    rs.$oOut.click(function () {
        $(this).data();
    });
    rs.$oEditnotice.click(function () {
        var $that = $(this),
            $info_tip = $('#info-tip'),
            roomData = $that.data();
        $.post("home/getRoomMain", { roomId: roomData.id }, function (data) {
            if (roomData.main == 1) {
                $info_tip.tips('notice', {
                    title: '群公告',
                    user_info: { show: true, name: data.name, time: data.notice_time, pic: data.url },
                    textarea: { id: 't1', text: data.notice, textMax: 40 },
                    confirm_txt: '发布',
                    confirm: function confirm(t) {
                        $info_tip.tips('tip', {
                            title: '群公告',
                            txt: '该公告会通知全部群成员,是否发布?',
                            btn_cancel: true,
                            confirm: function confirm() {
                                $.post("home/editNotice", { roomId: roomData.id, notice: t }, function () {
                                    send('@所有人\n' + t, roomData.id);
                                    scrolltToBottom();
                                    $that.text(t);
                                });
                            }
                        });
                    }
                });
            } else {
                $info_tip.tips('notice', {
                    title: '群公告',
                    user_info: { show: true, name: data.name, time: data.notice_time, pic: data.url },
                    textarea: { text: data.notice, textMax: 40 },
                    btn_disable: true
                });
            }
        });
    });
    Echo.channel('withDrawal').listen('WithDrawal', function (e) {
        var $dialogue = $('#info-content li.dialogue[data-id=\'' + e.dialogueId + '\']'),
            tip = '<div class="withDrawal-tip"><span>' + e.user.name + ' \u64A4\u56DE\u4E86\u4E00\u6761\u6D88\u606F</span></div>',
            index = parseInt($dialogue.index());
        if (sessionStorage[index]) sessionStorage[index] = tip;
        $dialogue.after(tip);
        $dialogue.remove();
        scrolltToBottom();
    });
    //room Setting
    $('.edit-notice,.rename-title').hover(function () {
        $(this).parent().children('em').show();
    }, function () {
        $(this).parent().children('em').hide();
    });
    !function ($, window, undefined) {
        var tips = function tips(el, options) {
            this.$el = el, this.defaults = {
                title: '提示',
                txt: '发送时间超过2分钟的消息，不能被撤回。',
                textarea: { id: null, text: '', textMax: 16 },
                user_info: { show: false, pic: '', name: '', time: '' },
                oConfirm: el.children('#confirm'),
                oCancel: el.children("#tip-close"),
                confirm: confirm,
                cancel: cancel,
                btn_cancel: false,
                confirm_txt: '确定',
                btn_disable: false
            }, this.opts = $.extend({}, this.defaults, options || {});
        };
        var cancel = function cancel() {
            this.oCancel.parent().hide();
        },
            confirm = function confirm() {
            this.oConfirm.parent().hide();
        };
        tips.prototype = {
            init: function init() {
                var opts = this.opts,
                    $el = this.$el,
                    $oTitle = $el.children('.title'),
                    $oBtnCancel = $el.children('#cancel'),
                    $oConfirm = $el.children('#confirm'),
                    $oInfo = $el.children('.notice-user-info'),
                    $oCancel = $el.children("#tip-close,#cancel");

                $oTitle.text(opts.title);
                $oConfirm.text(opts.confirm_txt);
                opts.user_info.show ? $oInfo.show() : $oInfo.hide();
                opts.btn_cancel ? $oBtnCancel.show() && $oConfirm.removeClass('btn-center') : $oBtnCancel.hide() && $oConfirm.addClass('btn-center');
                $oCancel.click(function () {
                    opts.cancel();
                });
                $oConfirm.unbind('click').click(function () {
                    $el.hide();
                    opts.confirm($('textarea#' + opts.textarea.id).val());
                });
                return $el.show();
            },
            tip: function tip() {
                var opts = this.opts,
                    $oCon = this.$el.children('.con');
                $oCon.html('<span class="tip">' + opts.txt + '</span>');
            },
            rename: function rename() {
                var opts = this.opts,
                    $oCon = this.$el.children('.con');
                $oCon.html('<textarea id="' + opts.textarea.id + '" class="rename" maxlength="' + opts.textarea.textMax + '">' + opts.textarea.text + '</textarea>');
                $('textarea#' + opts.textarea.id).attr('disabled', opts.btn_disable).focus();
            },
            notice: function notice() {
                var opts = this.opts,
                    $el = this.$el,
                    $oCon = $el.children('.con'),
                    $oConfirm = $el.children('#confirm'),
                    $oInfo = $el.children('.notice-user-info'),
                    textarea = '<textarea id="' + opts.textarea.id + '" class="edit-notice" maxlength="' + opts.textarea.textMax + '">' + opts.textarea.text + '</textarea>';

                $oInfo.children('img').attr('src', opts.user_info.pic);
                $oInfo.children('span.info').html(opts.user_info.name + '<br>' + opts.user_info.time);
                opts.btn_disable && ($oConfirm.remove(), $oCon.after('<span class="inline-word">仅群主可编辑</span>'));
                $oCon.html(textarea);
                $('textarea#' + opts.textarea.id).attr('disabled', opts.btn_disable).focus();
            },
            label: function label() {
                var opts = this.opts;
                this.$el.append('<div class="withDrawal-tip"><span>' + opts.txt + '</span></div>');
                scrolltToBottom();
                return this.$el;
            }
        };
        $.fn.tips = function (method, options) {
            var tip = new tips(this, options);
            //eval('tip.'+method+'()');
            if (method != 'label') tip.init();
            return tip[method]();
        };
    }(jQuery, window, undefined);
    /*begin addRoom*/
    !function ($, window, document, undefined) {
        var Room = function Room(el, options) {
            this.$el = el, this.$Close = el.children('.close-wrap,.cancel'), this.$Confirm = el.children('button#newRoom'), this.$from = el.children('.from-con').children('ul.from-list'), this.$to = el.children('.to-con').children('ul.to-list'), this.$tips = el.children('.to-con').children('span.tips'), this.defaults = {
                oConfirm: $('button#newRoom'),
                btn_confirm: { txt: '确定', class: 'chat-btn-green' },
                roomId: null,
                type: 0,
                confirm: confirm
            }, this.opts = $.extend({}, this.defaults, options || {});
        };
        var confirm = function confirm() {
            this.oConfirm.parent().hide();
        };
        Room.prototype = {
            init: function init() {
                var opts = this.opts,
                    $el = this.$el,
                    $Close = this.$Close,
                    $Confirm = this.$Confirm,
                    $from = this.$from,
                    $to = this.$to,
                    $tips = this.$tips;

                $from.html('');
                $.get('home/userList', { id: opts.roomId, type: opts.type }, function (data) {
                    var html = '';
                    $.each(data, function (i, v) {
                        html += '<span class="letter">' + i + '</span>';
                        $.each(v, function (i, v) {
                            html += '<div class="checkbox" data-id="' + v.id + '"><label>\n                                        <li class="li-list" data-id="' + v.id + '">\n                                        <img src="' + v.url + '" alt="">\n                                        <span>' + v.name + '</span>\n                                        <i class="cancel iconfont icon-jiaochacross78"></i>\n                                        </li>\n                                        <input data-id="' + v.id + '" class="check-item" type="checkbox" value="' + v.id + '">\n                                        </label>\n                                        </div>';
                        });
                    });
                    $from.html(html);
                });
                $Confirm.removeClass().addClass('chat-btn').addClass(opts.btn_confirm.class).text(opts.btn_confirm.txt);
                $el.show();
                $Close.click(function () {
                    $el.hide();
                    $to.html('');
                });
                $Confirm.unbind('click').click(function () {
                    var ids = [];
                    $to.children('li.li-list').each(function (i, v) {
                        ids.push(parseInt($(v).data('id')));
                    });
                    $el.hide();
                    opts.confirm(ids);
                    $to.html('');
                });
                $(document).unbind('change').on('change', '#' + $el.attr('id') + ' .check-item:checkbox', function () {
                    var html = $(this).prev('li.li-list')[0].outerHTML,
                        id = $(this).prev('li.li-list').data('id'),
                        num = $('#' + $el.attr('id') + ' input.check-item:checked').length;
                    num === 0 ? $tips.html('请勾选需要添加的联系人') && $Confirm.prop('disabled', true) : $tips.html('\u5DF2\u9009\u62E9\u4E86' + num + '\u4E2A\u8054\u7CFB\u4EBA') && $Confirm.prop('disabled', false);
                    $(this).is(':checked') ? $to.append(html) : $to.children('li[data-id=' + id + ']').remove();
                });
            }
        };
        $.fn.Room = function (options) {
            var room = new Room(this, options);
            return room.init();
            //return tip[method]();
        };
    }(jQuery, window, document, undefined);

    $(document).on('click', '.to-list li.li-list i.cancel', function () {
        var id = $(this).parent().data('id');
        $(this).parent().remove();
        $('.check-item:checkbox[data-id=' + id + ']').prop('checked', false);
    });
    $('.add-user').click(function () {
        $('#addUser-wrap').Room({
            confirm: function confirm(ids) {
                $.ajax({
                    type: 'get',
                    data: { ids: ids },
                    url: 'home/createRoom',
                    success: function success(data) {
                        var endFunc = function endFunc() {
                            $('.chat-setting i.chat').click();
                            $('.chat-side .chat-list li[data-id=' + data.room.id + ']').click();
                        };
                        if (data.flag) {
                            var room = data.room;
                            $('ul.chat-list').append('<li data-id="' + room.id + '">\n                                                <img src="' + room.url + '" alt="">\n                                                <div class="info">\n                                                    <span class="title">' + room.name + '</span>\n                                                   <span class="con"></span>\n                                               </div>\n                                               <div class="time">\n                                                   <time></time>\n                                               </div>\n                                           </li>');
                            endFunc();
                        } else {
                            endFunc();
                        }
                    }
                });
            }
        });
    });
    /*end addRoom*/
    /*side choose*/
    var sc = {
        $oChat: $('.chat-setting i.chat'),
        $oAdr: $('.chat-setting i.address-list'),
        $oCole: $('.chat-setting i.collection'),
        $user_list: $('.chat-side ul.user-list'),
        $chat_list: $('.chat-side ul.chat-list')
    };
    sc.$oChat.click(function () {
        if ($('li.choose').length > 0) {
            $chat_bg.hide();
            $chat_wrap.show();
        }
        sc.$user_list.hide();
        sc.$chat_list.show();
    });
    sc.$oAdr.unbind('click').click(function () {
        $chat_bg.show();
        $chat_wrap.hide();
        sc.$user_list.show();
        sc.$chat_list.hide();

        $.ajax({
            type: 'get',
            url: 'home/userList',
            success: function success(data) {
                var html = '';
                $.each(data, function (i, v) {
                    html += '<span class="letter">' + i + '</span>';
                    $.each(v, function (i, v) {
                        html += '<li class="li-list" data-id="' + v.id + '">\n                    <img src="' + v.url + '" alt="">\n                    <span>' + v.name + '</span>\n                    </li>';
                    });
                });
                sc.$user_list.html(html);
            }
        });
    });
    sc.$oCole.click(function () {
        //TODO:收藏
        console.log('TODO:收藏');
    });
    $('.chat-setting i.iconfont').click(function () {
        $(this).addClass('bg-color').siblings('i').removeClass('bg-color');
        rs.room_more_taggle = true;
        $('.room-setting').animate({
            'right': '0'
        }, 300);
    });
    /*end side choose*/
    /*#textarea*/
    var tp = {
        $textarea: $('div#textarea'),
        $btn_send: $('#send')
    };
    tp.$textarea.keydown(function (e) {
        var keycode = window.event ? e.keyCode : e.which,
            txt = $(this).html().trim();
        if (keycode == 13 && e.ctrlKey) {
            txt += "\n";
            $(this).html(txt);
        } else if (keycode == 13) {
            e.preventDefault();
            send(txt, sessionStorage.roomId);
        }
    });
    tp.$btn_send.click(function () {
        var txt = tp.$textarea.html().trim();
        send(txt, sessionStorage.roomId);
    });
    $(document).on('click', '#info-content .head-pic', function (e) {
        var id = $(this).data('id');
        $.ajax({
            type: "post",
            url: "home/getUserInfo",
            data: { 'id': id },
            success: function success(data) {
                var _data$user = data.user,
                    name = _data$user.name,
                    email = _data$user.email,
                    url = _data$user.url,
                    sex = _data$user.sex;

                $('.user-info .name').text(name);
                $('.user-info .count').text(email);
                $('.user-info .img-header').attr('src', url);
                $('.user-info .sex').attr('src', 'images/chat/' + sex + '.png');
            },
            error: function error(data) {
                console.log(data.responseJSON.errors);
            }
        });
        $('.user-info').css({
            left: e.pageX,
            top: e.pageY
        }).show();
    });
    $('.user-info').mouseleave(function () {
        $('.user-info').hide();
    });
    $(".dialoge-op").on("mousedown", function (e) {
        e.stopPropagation();
    });
    $(".chat-list-op").on("mousedown", function (e) {
        e.stopPropagation();
    });
    doms.$oNavBox.on("click", function (e) {
        e.stopPropagation();
    });
    $('#emotion img').click(function () {
        var $img = $(this),
            $input_box = $('div#textarea');
        $input_box.append($img);
        set_focus($input_box);
    });
    /*his*/
    /*start history*/
    $('#history #his-close').click(function () {
        $(this).parent('#history').hide();
    });
    $('#history #his-search').on('input propertychange', function (e) {
        var keyword = $('#his-search').val().toString().trim();
        $(".dropload-down").remove();
        var roomId = $('li.choose').data('id');
        dropload(keyword, roomId);
    });
    /*chat-list-op*/
    $(document).on('mousedown', '.chat-list li', function (e) {
        if (3 == e.which) {
            var roomId = $(this).data('id'),
                sort = $(this).data('sort'),
                per = $(this).data('per'),
                $this = $(this),
                $title_el = $(this).children('.info').children('span.title'),
                $con_el = $(this).children('.info').children('span.con'),
                $sort_el = $('.chat-list-op .sort'),
                $del_el = $('.chat-list-op .delete'),
                $rename_el = $('.chat-list-op .rename'),
                $ul_op = $('.chat-list-op');
            sort == 0 ? $sort_el.text('置顶') : $sort_el.text('取消置顶');
            per == 1 ? $rename_el.hide() : $rename_el.show();
            $ul_op.show().css({
                left: e.pageX,
                top: e.pageY
            });
            $(document).one("mousedown", function (e) {
                $ul_op.hide();
            });
            e.stopPropagation();
            $sort_el.unbind('click').click($this, function () {
                var $chatList = $('.chat-list');
                $.post("home/roomSort", { roomId: roomId }, function (data) {
                    $ul_op.hide();
                    $this.data('sort', data);
                    if (data == 1) {
                        $this.hide().show().addClass('top');
                        $chatList.prepend($this);
                    } else {
                        $this.hide().show().removeClass('top');
                        $chatList.append($this);
                    }
                });
            });
            $del_el.unbind('click').click(function () {
                $.post("home/roomDelete", { roomId: roomId }, function (data) {
                    $ul_op.hide();
                    $('.chat-list li[data-id=' + roomId + ']').remove();
                });
            });
            $rename_el.unbind('click').click(function () {
                var title = $title_el.text(),
                    $infoCon = $('#info-content'),
                    $infoTip = $('#info-tip');
                $ul_op.hide();
                $infoTip.tips('rename', {
                    title: '修改群名称',
                    textarea: { id: 't2', text: title, textMax: 16 },
                    btn_cancel: true,
                    confirm: function confirm(t) {
                        $.post("home/roomRename", { roomId: roomId, title: t }, function (data) {
                            $title_el.text(t);
                            var txt = '\u4F60\u4FEE\u6539\u7FA4\u540D\u4E3A' + t;
                            $con_el.text(txt);
                            if ($this.hasClass("choose")) {
                                $infoCon.tips('label', { txt: txt });
                                doms.$oTitle.text(t);
                                scrolltToBottom();
                            }
                        });
                    }
                });
            });
        }
    });

    /*room-list-op*/
    $(document).on('click', '.chat-side .chat-list li', function () {
        var room_id = $(this).data('id'),
            $oTitle = $(this).children('div.info').children('span.title'),
            $oCon = $('#info-content');
        if ($('li.choose').length == 0) {
            $chat_bg.hide();
            $chat_wrap.show();
        }
        doms.$oTitle.html($oTitle.text());
        sessionStorage.roomId && Echo.leave('chat.' + sessionStorage.roomId);
        sessionStorage.roomId = parseInt(room_id);
        if ($(this).hasClass('choose')) {
            return false;
        } else {
            Echo.join('chat.' + sessionStorage.roomId).here(function (users) {
                console.log(users.length);
            }).joining(function (user) {
                if ($('li.choose').data('id') == user.roomId) {
                    $oCon.tips('label', { txt: user.name + ' 加入房间' });
                    scrolltToBottom();
                }
            }).leaving(function (user) {
                if ($('li.choose').data('id') == user.roomId) {
                    $oCon.tips('label', { txt: user.name + ' 离开房间' });
                    scrolltToBottom();
                }
            }).listen('Event', function (e) {
                var user = Object.assign(e.user, { time: e.time, url: e.url }),
                    id = $('li.choose').data('id'),
                    args = { rId: e.roomId, dlgId: e.dialogueId, user: user, txt: e.txt, role: 'ans' };
                if (args.dlgId < 0) {
                    if (args.dlgId === -1) {
                        $oCon.tips('label', { txt: user.name + '\u4FEE\u6539\u4E86\u7FA4\u540D\u4E3A "' + args.txt + '"' });
                        $('.chat-list li[data-id=' + args.rId + '] .info span.title').text(args.txt);
                        id == args.rId && doms.$oTitle.text(args.txt);
                    } else if (args.dlgId === -2) {
                        $oCon.tips('label', { txt: args.user.name + '\u9080\u8BF7"' + args.txt.join(',') + '"\u52A0\u5165\u7FA4\u804A' });
                        //TODO:console.log(args.txt[0].includes(3))
                    } else if (args.dlgId === -3) {
                        $oCon.tips('label', { txt: '"' + args.user.name + '"\u9000\u51FA\u7FA4\u804A' });
                    }
                } else {
                    dialoge(args);
                }
                scrolltToBottom();
            });
            $.ajax({
                type: 'get',
                url: 'home/chatList/' + room_id,
                success: function success(data) {
                    if (data.list) {
                        var html = '';
                        data.list.forEach(function (v) {
                            html += '<li class="dialogue ' + v.role + '" data-id="' + v.id + '">\n                                <img data-id="' + v.user_id + '" class="head-pic" src="' + v.url + '" title="\u70B9\u51FB\u67E5\u770B\u7528\u6237\u4FE1\u606F">\n                                <em></em>\n                                <div class="txt" data-self="' + v.user_id + '" data-id="' + v.id + '">' + v.txt + '\n                                </div>\n                                <span class="time">' + v.time + '</span>\n                                 </li>';
                        });
                        doms.$oCon.html(html);
                        scrolltToBottom();
                    }
                    var $oUl = $('ul.room-users'),
                        $oIn = $('.room-op input.rename-title'),
                        $oSpan = $('.room-op span.edit-notice'),
                        $oGroups = $('.room-op div.group-op'),
                        $oOut = $('.room-setting .out'),
                        add = '<li class="add"><div data-id="' + room_id + '" data-type="' + data.room.type + '"  id="plus">\uFF0B</div><span>\u6DFB\u52A0</span></li>',
                        del = '<li class="delete"><div data-id="' + room_id + '" id="reduce">\uFF0D</div><span>\u5220\u9664</span></li>';
                    if (data.users != 0) {
                        var _html = data.isMain == 1 ? add + del : add;
                        data.users.forEach(function (v) {
                            _html += '<li data-id="' + v.id + '"><img src="' + v.url + '" alt=""><span>' + v.name + '</span></li>';
                        });
                        $oUl.html(_html);
                        $oGroups.show();
                        $oOut.show();
                        data.room.name != '群聊' ? $oIn.val(data.room.name) : $oIn.val('');
                        $oIn.data('id', room_id);
                        $oSpan.data('main', data.isMain);
                        $oSpan.data('id', room_id);
                        $oOut.data('main', data.isMain);
                        data.isMain == 0 ? $oOut.text('退出群聊') : $oOut.text('删除并退出');
                        data.isMain == 0 && data.room.notice === null && $oSpan.unbind('click');
                        $oSpan.text(data.room.notice === null ? data.isMain == 1 ? '点击编辑群公告' : '暂无群公告' : '@\u6240\u6709\u4EBA ' + data.room.notice);
                    } else {
                        var _html2 = add + '<li><img src="' + data.user.url + '" alt=""><span>' + data.user.name + '</span></li>';
                        $oUl.html(_html2);
                        $oGroups.hide();
                        $oOut.hide();
                    }
                    $oOut.data('id', room_id);
                }
            });
        }
        $(this).addClass('choose').siblings().removeClass('choose');
        var roomId = $('li.choose').data('id'),
            $ss = $('#sessionStorage');
        typeof sessionStorage[roomId] === 'undefined' ? $ss.html('') : $ss.html(sessionStorage[roomId]);
    });

    /*dialogue-op*/
    $(document).on('mousedown', '.dialogue .txt', function (e) {
        if (3 === e.which) {
            var $this = $(this),
                $oCon = $this.parents('#info-content'),
                $oHis = $this.parents('#info-history'),
                $dialogue = $this.parent('li.dialogue'),
                $d_op = $('.dialoge-op'),
                $oWithdrawal = $d_op.children('.withdrawal'),
                $oClear = $d_op.children('.clear'),
                $oDelete = $d_op.children('.delete'),
                id = parseInt($this.data('id')),
                self = parseInt($this.data('self'));
            $dialogue.hasClass('ask') && $oCon.length > 0 ? ($oWithdrawal.show(), $oClear.show()) : ($oWithdrawal.hide(), $oClear.hide());
            $oHis.length > 0 && (1 === self ? $oDelete.show() : $oDelete.hide());
            $d_op.show().css({
                left: e.pageX,
                top: e.pageY
            });
            $(document).one("mousedown", function (e) {
                $d_op.hide();
            });
            e.stopPropagation();
            //删除
            $oDelete.unbind('click').click($this, function () {
                $d_op.hide();
                var isSoftDel = typeof $this.data('type') === 'undefined' ? 1 : 0;
                var index = parseInt($dialogue.index());
                $.post("home/deleteDialogue", { id: id, isSoftDel: isSoftDel }, function () {
                    $this.parent('li.dialogue').remove();
                    if (isSoftDel == 0) $('li.dialogue[data-id=' + id + ']').remove();
                });
            });
            //撤回
            $oWithdrawal.unbind('click').click($this, function (e) {
                var index = parseInt($dialogue.index());
                $d_op.hide();
                $.post("home/withdrawal", { id: id }, function (data) {
                    if (data.flag) {
                        $dialogue.after('<div class="withDrawal-tip"><span>你撤回了一条消息</span></div>');
                        $dialogue.remove();
                    } else {
                        $('#info-tip').tips('tip');
                    }
                });
            });
            //清屏
            $oClear.unbind('click').click(function (e) {
                $d_op.hide();
                $oCon.children().remove();
                var roomId = $('.chat-side li.choose').data('id');
                if (sessionStorage[roomId]) {
                    sessionStorage.removeItem(roomId);
                }
            });
        }
    });
});

/***/ })

/******/ });